package com.CmJava.servlet.handlerMapping;

import com.CmJava.servlet.DispatcherServlet;
import com.CmJava.servlet.executionChain.HandlerExecutionChain;
import com.CmJava.servlet.executionChain.handlerMethodMapping.AbstractHandlerMethodMapping;
import com.CmJava.servlet.executionChain.handlerMethodMapping.HandlerMethod;

import javax.servlet.http.HttpServletRequest;

/**
 * @RequestMapping的方法都会成为该类
 *
 */
public class RequestMappingHandlerMapping implements HandlerMapping {

    public HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
        Object handler = this.getHandlerInternal(request);
        HandlerExecutionChain executionChain = this.getHandlerExecutionChain(handler, request);
        return executionChain;
        }

    private HandlerExecutionChain getHandlerExecutionChain(Object handler, HttpServletRequest request) {
        return new HandlerExecutionChain(handler);
    }



    private Object getHandlerInternal(HttpServletRequest request) {
        AbstractHandlerMethodMapping abstractHandlerMethodMapping = DispatcherServlet.abstractHandlerMethodMapping;
        HandlerMethod handlerMethod=null;
        try {
            handlerMethod = abstractHandlerMethodMapping.getHandlerInternal(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return handlerMethod;
    }
}
